package testcase.cell;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import junitx.util.PrivateAccessor;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import satir.card.Card;
import satir.card.Deck;
import satir.cell.EventCell;
import satir.player.Player;

/**
 * The Testing Class EventCell_cellAction.
 * 
 * @version 1.0 March 2012
 * @author Bill Chan
 * 
 */
public class EventCell_cellAction extends TestCase{
	private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); 
	private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); 
	
	/**
	 * Sets up the test fixture.
	 * 
	 * Called before every test case method.
	 */
	@Before
	public void setUp() throws Exception {
		   System.setOut(new PrintStream(outContent));     
		   System.setErr(new PrintStream(errContent)); 
	}
	
	/**
	 * Tears down the test fixture.
	 * 
	 * Called after every test case method.
	 */
	@After
	public void tearDown() throws Exception {
		   System.setOut(null);     
		   System.setErr(null); 
	}

	/**
	 * Step number: 1 
	 * Goal: Test whether it can get an event card or not
	 */
	@Test
	public void testCellAction() {
		class DeckStub extends Deck{
			public Card drawCard() {
				return new Card(){

					@Override
					protected void doActivateCard(Player p) {
						System.out.print("testing");						
					}
					
					@Override
					public void activateCard(Player p){
						doActivateCard(p);
					}};
			}
		}

		Player player=new Player();
		EventCell eventCell=new EventCell(0, 0, '0', '0', null);
		
		try {
			PrivateAccessor.setField(eventCell, "deck", new DeckStub());
		} catch (NoSuchFieldException e1) {
			e1.printStackTrace();
		}
		eventCell.cellAction(player);
		assertEquals("testing", outContent.toString());
	}
}
